<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-01-11 20:01:09
 * @Last Modified time: 2023-02-17 15:25:46
 */
namespace app\api\controller\common;	
use frank\base\BaseController;
use app\api\services\store\DiyPageService;
use frank\services\FileUploadService;
use app\common\utils\store\DiyPageUtils;

/**
 * Class Publics
 */
class Publics extends \app\api\controller\Base
{ 	
    /**
     * 获取首页
     * @force(false)
     * @method(GET)
     */
    public function diyData()
    {
        $data['user'] = sysconf('store_diy_user|json');
        $data['page'] = DiyPageService::instance()->getApiHome($this->user)['page_data'] ?? [];
        $data['theme'] = DiyPageUtils::getThemes(sysconf('store_diy_theme'));
        $data['categroy'] = sysconf('store_diy_categroy');
        $data['payment'] = [
            'wechatpay'=>sysconf('wechatpay_status'),
            'walletpay'=>sysconf('walletpay_status'),
        ];
        $this->success($data);
    }

    /**
     * 上传图片
     * @force(false)
     * @method(POST)
     */
    public function uploadCacheImage()
    {
        $service = FileUploadService::instance();
        $service->setCachePath('uploads');
        if($data = $service->cacheImagem(["name" => "image"])){
            $this->success('上传成功',$data);
        }
        $this->error($service->getError() ?: '上传失败');
    }
}
